﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HotelManagement._04.OBJECT;
using HotelManagement._02.BUS;
using HotelManagement;


namespace HotelManagement._01.FORM
{
    public partial class F31_Room : Form
    {
        Room m_Room;
        RoomBUS m_RoomBUS;
        
        public F31_Room()
        {
            InitializeComponent();
            Init();
            LoadData();
            if (AssetsGS.instance.RoleUser == "User")
            {
                m_btn_Update.Enabled = false;
            }
        }

        public void Init()
        {
            m_Room = new Room();
            m_RoomBUS = new RoomBUS();
        }

        public void LoadData()
        {
            m_dgv_RoomInfo.DataSource = m_RoomBUS.ViewRoomInfo();
            m_cbo_RoomType.DataSource = m_RoomBUS.SelectToComboBox();
            m_cbo_RoomType.DisplayMember = "RoomTypeDescription";
            m_cbo_RoomType.ValueMember = "RoomTypeID";
        }

        private void m_dgv_RoomInfo_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                m_Room.RoomID = m_dgv_RoomInfo.Rows[m_dgv_RoomInfo.CurrentCell.RowIndex].Cells["RoomID"].Value.ToString();
                m_Room.RoomTypeID = int.Parse(m_dgv_RoomInfo.Rows[m_dgv_RoomInfo.CurrentCell.RowIndex].Cells["RoomTypeID"].Value.ToString());
                m_Room.Status = m_dgv_RoomInfo.Rows[m_dgv_RoomInfo.CurrentCell.RowIndex].Cells["Status"].Value.ToString();
                m_Room.Note = m_dgv_RoomInfo.Rows[m_dgv_RoomInfo.CurrentCell.RowIndex].Cells["Note"].Value.ToString();
                m_Room.RoomTypeDescription = m_dgv_RoomInfo.Rows[m_dgv_RoomInfo.CurrentCell.RowIndex].Cells["RoomTypeDescription"].Value.ToString();
                m_Room.Floor = int.Parse(m_dgv_RoomInfo.Rows[m_dgv_RoomInfo.CurrentCell.RowIndex].Cells["Floor"].Value.ToString());

                m_txt_RoomID.Text = m_Room.RoomID;
                m_txt_Floor.Text = m_Room.Floor.ToString();
                m_txt_Note.Text = m_Room.Note;
                m_cbo_Status.Text = m_Room.Status;
                m_cbo_RoomType.Text = m_Room.RoomTypeDescription;
            }
            catch
            {

            }
        }

        private void m_btn_Update_Click(object sender, EventArgs e)
        {
            if (m_Room.RoomID == null)
            {
                MessageBox.Show("Bạn chưa chọn phòng nào!");
            }
            else
            {
                DialogResult OK;
                OK = MessageBox.Show("Bạn muốn cập nhật thông tin cho phòng đã chọn ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (OK == DialogResult.Yes)
                {
                    m_Room.Floor = int.Parse(m_txt_Floor.Text.ToString());
                    m_Room.Note = m_txt_Note.Text.ToString();
                    m_Room.Status = m_cbo_Status.Text.ToString().Trim();
                    if (m_RoomBUS.UpdateRoomInfo(m_Room))
                    {
                        MessageBox.Show("Thành công !");
                        LoadData();
                    }
                    else MessageBox.Show("Có lỗi! Không cập nhật được.");
                }
            }
        }

        private void m_cbo_RoomType_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                m_Room.RoomTypeID = int.Parse(m_cbo_RoomType.SelectedValue.ToString());
            }
            catch (Exception ex)
            {

            }
        }

        private void m_btn_Search_Click(object sender, EventArgs e)
        {
            string v_RoomID = m_txt_Search.Text.ToString().Trim();
            m_dgv_RoomInfo.DataSource = m_RoomBUS.ViewRoomSearch(v_RoomID);
        }

        private void m_btn_Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void m_btn_RoomStatus_Click(object sender, EventArgs e)
        {
            F33_RoomStatus v_F33_RoomStatus = new F33_RoomStatus();
            v_F33_RoomStatus.ShowDialog();
        }



    }
}
